/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package visao.pedido;

import controle.modelo.ControlePedido;
import java.util.Calendar;
import javax.swing.table.DefaultTableModel;
import modelo.Linha;
import modelo.Pedido;

/**
 *
 * @author luiz.filho
 */
public class DetalhamentoDePedidoForm extends javax.swing.JFrame
{

    Pedido thisPedido;
    ControlePedido controlePedido;

    /**
     * Creates new form DetalhamentoDePedidoForm
     */
    public DetalhamentoDePedidoForm(Integer idPedido)
    {
        initComponents();
        controlePedido = new ControlePedido();
        thisPedido = controlePedido.getPedidoById(idPedido);

        NumeroPedidoValor.setText(String.valueOf(thisPedido.getIdPedido()));
        ValorTotalValor.setText(thisPedido.getValorTotal().toString());
        String dayOfTheMonth = String.valueOf(thisPedido.getCalendar().get(Calendar.DAY_OF_MONTH));
        String month = String.valueOf(thisPedido.getCalendar().get(Calendar.MONTH) + 1);
        String year = String.valueOf(thisPedido.getCalendar().get(Calendar.YEAR));

        DataDoPedidoValor.setText(dayOfTheMonth + "/" + month + "/" + year);
        TipoDePagamentoValor.setText(thisPedido.getTipoDePagamento().getDescricao());

        if (thisPedido.getCliente() == null)
        {
            ClienteValor.setText("PEDIDO VAREJO");
        }
        else
        {
            ClienteValor.setText(thisPedido.getCliente().getNome());
        }

        String[] columnNames =
        {
            "Produto", "Quantidade", "Valor do Produto", "Valor total do Item"
        };
        String[][] data = new String[thisPedido.getLinhas().size()][4];
        for (int i = 0; i < thisPedido.getLinhas().size(); i++)
        {
            Linha linha = thisPedido.getLinhas().get(i);
            
            data[i][0] = linha.getProduto().getDescricao();
            data[i][1] = linha.getQuantidade().toString();
            if(thisPedido.getCliente() == null)
                data[i][2] = linha.getProduto().getPrecoVarejo().toString();
            else
                data[i][2] = linha.getProduto().getPrecoRevenda().toString();
            data[i][3] = String.valueOf(Double.valueOf(data[i][2]) * linha.getQuantidade());
        }
        jTable1.setModel(new DefaultTableModel(data, columnNames));

    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents()
    {

        NumeroPedidoIndicador = new javax.swing.JLabel();
        NumeroPedidoValor = new javax.swing.JLabel();
        ValorTotalIndicador = new javax.swing.JLabel();
        ValorTotalValor = new javax.swing.JLabel();
        DataDoPedidoIndicador = new javax.swing.JLabel();
        TipoDePagamentoIndicador = new javax.swing.JLabel();
        TipoDePagamentoValor = new javax.swing.JLabel();
        DataDoPedidoValor = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jButton1 = new javax.swing.JButton();
        ClienteIndicador = new javax.swing.JLabel();
        ClienteValor = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        NumeroPedidoIndicador.setText("Pedido numero: ");

        NumeroPedidoValor.setText("jLabel2");

        ValorTotalIndicador.setText("Valor Total: ");

        ValorTotalValor.setText("jLabel2");

        DataDoPedidoIndicador.setText("Data do pedido: ");

        TipoDePagamentoIndicador.setText("Tipo de Pagamento: ");

        TipoDePagamentoValor.setText("jLabel3");

        DataDoPedidoValor.setText("jLabel4");

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][]
            {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String []
            {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane1.setViewportView(jTable1);

        jButton1.setText("Sair");
        jButton1.addActionListener(new java.awt.event.ActionListener()
        {
            public void actionPerformed(java.awt.event.ActionEvent evt)
            {
                jButton1ActionPerformed(evt);
            }
        });

        ClienteIndicador.setText("Cliente: ");

        ClienteValor.setText("jLabel2");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 582, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                .addComponent(NumeroPedidoIndicador)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(NumeroPedidoValor))
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(ValorTotalIndicador)
                                    .addComponent(DataDoPedidoIndicador))
                                .addGap(25, 25, 25)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(DataDoPedidoValor)
                                    .addComponent(ValorTotalValor))))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jButton1))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(TipoDePagamentoIndicador)
                            .addComponent(ClienteIndicador))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(ClienteValor)
                            .addComponent(TipoDePagamentoValor))
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(NumeroPedidoIndicador)
                            .addComponent(NumeroPedidoValor))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(ValorTotalIndicador)
                            .addComponent(ValorTotalValor)))
                    .addComponent(jButton1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(DataDoPedidoIndicador)
                    .addComponent(DataDoPedidoValor))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(TipoDePagamentoIndicador)
                    .addComponent(TipoDePagamentoValor))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(ClienteIndicador)
                    .addComponent(ClienteValor))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 57, Short.MAX_VALUE)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 368, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButton1ActionPerformed
    {//GEN-HEADEREND:event_jButton1ActionPerformed
        dispose();
    }//GEN-LAST:event_jButton1ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[])
    {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try
        {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels())
            {
                if ("Nimbus".equals(info.getName()))
                {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        }
        catch (ClassNotFoundException ex)
        {
            java.util.logging.Logger.getLogger(DetalhamentoDePedidoForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        catch (InstantiationException ex)
        {
            java.util.logging.Logger.getLogger(DetalhamentoDePedidoForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        catch (IllegalAccessException ex)
        {
            java.util.logging.Logger.getLogger(DetalhamentoDePedidoForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        catch (javax.swing.UnsupportedLookAndFeelException ex)
        {
            java.util.logging.Logger.getLogger(DetalhamentoDePedidoForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable()
        {
            public void run()
            {
//                new DetalhamentoDePedidoForm().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel ClienteIndicador;
    private javax.swing.JLabel ClienteValor;
    private javax.swing.JLabel DataDoPedidoIndicador;
    private javax.swing.JLabel DataDoPedidoValor;
    private javax.swing.JLabel NumeroPedidoIndicador;
    private javax.swing.JLabel NumeroPedidoValor;
    private javax.swing.JLabel TipoDePagamentoIndicador;
    private javax.swing.JLabel TipoDePagamentoValor;
    private javax.swing.JLabel ValorTotalIndicador;
    private javax.swing.JLabel ValorTotalValor;
    private javax.swing.JButton jButton1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    // End of variables declaration//GEN-END:variables
}
